home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_jade.idb / usr / freeware / include / sp / lib / Trie.h.z / Trie.h
Encoding:
C/C++ Source or Header  |  1999-07-21  |  1.6 KB  |  71 lines

  1. // Copyright (c) 1994 James Clark
  2. // See the file COPYING for copying permission.
  3.  
  4. #ifndef Trie_INCLUDED
  5. #define Trie_INCLUDED 1
  6.  
  7. #include <limits.h>
  8. #include "types.h"
  9. #include "Boolean.h"
  10. #include "Vector.h"
  11. #include "CopyOwner.h"
  12. #include "Priority.h"
  13.  
  14. #ifdef SP_NAMESPACE
  15. namespace SP_NAMESPACE {
  16. #endif
  17.  
  18. class BlankTrie;
  19.  
  20. class Trie {
  21. public:
  22.   Trie() : next_(0), nCodes_(0) { }
  23.   Trie(const Trie &);
  24.   ~Trie();
  25.   Trie &operator=(const Trie &);
  26.   const Trie *next(int i) const { return &next_[i]; }
  27.   Boolean hasNext() const { return next_ != 0; }
  28.   Token token() const { return token_; }
  29.   int tokenLength() const { return tokenLength_; }
  30.   const BlankTrie *blank() const;
  31.   Boolean includeBlanks() const {
  32.     return Priority::isBlank(priority_);
  33.   }
  34.   friend class TrieBuilder;
  35. private:
  36.   Trie *next_;
  37.   int nCodes_;
  38.   unsigned short token_;
  39.   unsigned char tokenLength_;
  40.   Priority::Type priority_;
  41.   CopyOwner<BlankTrie> blank_;
  42. };
  43.  
  44. class BlankTrie : public Trie {
  45. public:
  46.   BlankTrie() { }
  47.   Boolean codeIsBlank(EquivCode c) const { return codeIsBlank_[c]; }
  48.   // maximum number of blanks to scan (minimum is 0)
  49.   size_t maxBlanksToScan() const { return maxBlanksToScan_; }
  50.   // length to add to tokenLengths in this trie (for those > 0).
  51.   int additionalLength() const { return additionalLength_; }
  52.   BlankTrie *copy() const { return new BlankTrie(*this); }
  53. private:
  54.   unsigned char additionalLength_;
  55.   size_t maxBlanksToScan_;
  56.   Vector<PackedBoolean> codeIsBlank_;
  57.   friend class TrieBuilder;
  58. };
  59.  
  60. inline
  61. const BlankTrie *Trie::blank() const
  62. {
  63.   return blank_.pointer();
  64. }
  65.  
  66. #ifdef SP_NAMESPACE
  67. }
  68. #endif
  69.  
  70. #endif /* not Trie_INCLUDED */
  71.